home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4195 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.1 KB

  1. Path: news.eznet.net!usenet
  2. From: Joe Mihalich <mihalich@eznet.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: VC++ 4.0 and Templates and the Compiler
  5. Date: Sat, 27 Jan 1996 14:26:12 -0500
  6. Organization: E-Znet Inc. Rochester N.Y. 14623 (716)-262-2485
  7. Message-ID: <310A7C54.4518@eznet.net>
  8. NNTP-Posting-Host: dialin-03.eznet.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b5 (WinNT; I)
  13.  
  14. Hi,
  15.  
  16.        Anyone who can answer this question will be the hero of
  17.     the year.  I am using Visual C++ 4.0 on both WIN NT and WIN 95.
  18.  
  19.        I have defined a class template that is derived from the
  20.     MFC class CString.  The class template is defined in a DLL.
  21.     In order for ALL of the functions to be exported properly,
  22.     they have to be instantiated via the compiler.
  23.  
  24.        Now, not all of the functions are being called from within
  25.     the DLL, so the compiler is not instantiating them, which
  26.     is not allowing me to call those functions from another
  27.     DLL or APP.
  28.  
  29.        Microsoft provides 3 ways of solving this problem:
  30.  
  31.         1) Declare/Define all functions in your class or it's
  32.            .h file.  All functions defined there are considered
  33.            inline and are automatically instantiated.  For 
  34.            example:
  35.  
  36.            //MyString.h
  37.  
  38.            template <class TYPE> class CMyString : public CString
  39.            {
  40.            TYPE Left(int nStart)
  41.               { return (TYPE)CString::Left(nStart); }
  42.            TYPE Left(int nStart, int nCount)
  43.               { return (TYPE)CString::Left(nStart, nCount); }
  44.            };
  45.  
  46.         This is the ideal method for me to use, but it DOES NOT
  47.             WORK.  All of my functions are defined in the .h files
  48.          cuz there not doing anything but calling the base class
  49.         functions.  The only functions that get instantiated are
  50.         the ones that are called from within the DLL.  I can verify
  51.         this via the .MAP file.
  52.  
  53.         2) In the source file where the functions are defined, reference
  54.            the function somewhere by taking it's address.  I tried this,
  55.            but couldn't get it to work either.  This method I probably 
  56.            screwed up, cuz I didn't know how to get the address of a function
  57.            when there were multiple overloaded versions of the function.
  58.            Any suggestions of how to do this?  For example:
  59.  
  60.            //MyString.h
  61.  
  62.            template <class TYPE> class CMyString : public CString
  63.            {
  64.            TYPE Left(int nStart)
  65.               { return (TYPE)CString::Left(nStart); }
  66.            TYPE Left(int nStart, int nCount)
  67.               { return (TYPE)CString::Left(nStart, nCount); }
  68.            void Dummy(void);
  69.            };
  70.  
  71.            Now, how do I take the address of either of the LEFT functions?
  72.  
  73.            //MyString.cpp
  74.         
  75.            CMyString::Dummy(void)
  76.            {
  77.           pFunction1 = &this->Left(int nStart);
  78.           pFunction2 = &this->Left(int nStart, int nCount);
  79.            }
  80.            
  81.             Is that correct?  If it is, than this method did not work
  82.            for me either!
  83.     
  84.         3) Create a dummy function in your base class that calls all
  85.            functions.  The dummy function does not need to be
  86.            called by anyone.  For Example:
  87.         
  88.         CMyString::Dummy(void)
  89.         {
  90.            this->Left(0);
  91.            this->Left(0,0);
  92.         }
  93.            
  94.            Unfortunately this is the only method that worked for me.  I consider
  95.            this to be an unacceptable solution because it just seems ludicrous
  96.            to have to do it this way.
  97.  
  98.  
  99.         If anyone has any ideas on how to make the first solution work, I 
  100.         would appreciate it.  I am assuming that there is some stupid 
  101.         compiler option that is turning off the expansion of inline
  102.         functions or something.  (Bye the way, I tried fooling around with
  103.         the compiler option in (C/C++ - Optimizations in the build settings
  104.         dialog) called "Inline function expansion".  The possible options
  105.         are: disabled, Inline Functions, Any suitable function.  For debug
  106.         mode, this option is always set to disabled.  I tried setting it
  107.         to either of the other two, but it didn't change anything.  The help
  108.         says that this option is just a suggestion to the compiler anyway.
  109.  
  110.         Any help will be greatly appreciated.
  111.  
  112.         Thanks,
  113.         Joe Mihalich
  114.  
  115. -- 
  116.     Joe Mihalich
  117.     Email: mihalich@eznet.net
  118.     Voice: 716-482-0089
  119.